package interview.huawei.myself.online1.v1;

import java.util.Random;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * @Author CandyWall
 * @Date 2022/3/10--15:30
 * @Description
 */
public class Producer implements Runnable {
    private LinkedBlockingQueue<Integer> queue;
    public Producer(LinkedBlockingQueue<Integer> queue) {
        this.queue = queue;
    }

    @Override
    public void run() {
        Random random = new Random();
        while (true) {
            int num = random.nextInt(100);
            System.out.println(Thread.currentThread().getName() + "：生产了 " + num);
            queue.add(num);
            try {
                TimeUnit.MILLISECONDS.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
